// pages/tobeTzEditOpenTime/tobeTzEditOpenTime.js
let ubt_js = require("../../utils/ubt.js");
let name_js = require("../../utils/ubtButtonName.js");
let common_js = require("../../utils/common.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    submitInfo: {
      begin: '',
      end: '',
      score: 0,
      isSureEnable: false
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //业务埋点
    ubt_js.myPageView(common_js.currentPageName(), options);
    //1.禁止转发
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    // 业务埋点
    ubt_js.myPageViewOut(common_js.currentPageName());
  },

  //开始时间
  onBegin: function(e) {
    let tmp = e.detail.detail.value;
    let tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.begin.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.begin.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.begin = tmp;
    if (tmpSubmitInfo.score == 2) {
      tmpSubmitInfo.isSureEnable = true;
    } else {
      tmpSubmitInfo.isSureEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //结束时间
  onEnd: function(e) {
    let tmp = e.detail.detail.value;
    let tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.end.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.end.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.end = tmp;
    if (tmpSubmitInfo.score == 2) {
      tmpSubmitInfo.isSureEnable = true;
    } else {
      tmpSubmitInfo.isSureEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //点击确定
  onSure: function() {
    //调用方法，返回上一页
    let pages = getCurrentPages();
    let prePage = pages[pages.length - 2];
    prePage.updateOpenTime(this.data.submitInfo);
    //返回
    wx.navigateBack({});
  }
})